AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')

function ENT:Initialize()
        RD_Register(self, true)--For Environments Compatibility

end

function ENT:Damage()
	if (self.damaged == 0) then
		self.damaged = 1
	end
end

function ENT:MakeBullet(Damage, Explodes, Spread, Force, Number)
	local vStart = self.Entity:GetPos()
	local vForward = self.Entity:GetForward()
			
	local Bullet = {}
	Bullet.Num = Number
	Bullet.Src = self.Entity:GetPos()
	Bullet.Dir = self.Entity:GetForward() --Position * -1
	Bullet.Spread = Vector( Spread, Spread, Spread )
	Bullet.Tracer = 1
	Bullet.Force = Force
	Bullet.TracerName = "Tracer"
	Bullet.Attacker = self.SPL
	Bullet.Damage = Damage
	if Explodes>0 then
		Bullet.Callback = function (attacker, tr, dmginfo)
			util.BlastDamage(self.Entity, self.Entity, tr.HitPos, 100, 100)
			gcombat.hcgexplode( tr.HitPos, 100, math.Rand(150, 300), 8)
			local effectdata = EffectData()
			effectdata:SetOrigin(tr.HitPos)
			effectdata:SetStart(tr.HitPos)
			util.Effect( "explosion", effectdata )
		end
	end
	self:FireBullets(Bullet)
end

function ENT:MakeShell(CCD,Size,Pos,Ang,Vel)
	local NewShell = ents.Create(Size)	
	if ( !NewShell:IsValid() ) then return end
	NewShell:SetPos(Pos)
	NewShell:SetAngles(Ang)
	NewShell.SPL = self.SPL
	NewShell:Spawn()
	NewShell:Initialize()
	local Col = self.TrailColor
	local Dam = self.Damage
	NewShell:Setup(Col,Dam)
	NewShell:Activate()
	NewShell:SetOwner(self)
	NewShell.PhysObj:SetVelocity(Vel)
	NewShell:Fire("kill", "", 30)
	NewShell.ParL = self.Entity
end

function ENT:MakeEnt(Ent,Pos,Ang)
	local NewEnt = ents.Create(Ent)
	if ( !NewEnt:IsValid() ) then return end
	NewEnt:SetPos(Pos)
	NewEnt:SetAngles(Ang)
	NewEnt:Spawn()
	NewEnt:Initialize()
	NewEnt:Activate()
	NewEnt:SetOwner(self)
end

function ENT:Recoil(Force)
	local phys = self.Entity:GetPhysicsObject()  	
	if (phys:IsValid()) then  		
		phys:ApplyForceCenter( self.Entity:GetForward() * -Force ) 
	end 
end

function ENT:Repair()
	self.Entity:SetColor(255, 255, 255, 255)
	self.health = self.maxhealth
	self.damaged = 0
end

function ENT:Destruct()
end

function ENT:Use( pl)
end

function ENT:OnRemove()

end

function ENT:Think()
	self.BaseClass.Think(self)
	if not (WireAddon == nil) then 
		self:UpdateWireOutput()
	end
	
	self.Entity:NextThink(CurTime() + 1)
	return true
end

function ENT:UpdateWireOutput()
end

function ENT:Touch( ent )
	if ent.HasHardpoints then
		if ent.Cont and ent.Cont:IsValid() then HPLink( ent.Cont, ent.Entity, self.Entity ) end
	end
end

function ENT:PreEntityCopy()
	if WireAddon then
		duplicator.StoreEntityModifier(self,"WireDupeInfo",WireLib.BuildDupeInfo(self.Entity))
	end
end

function ENT:PostEntityPaste(ply, ent, createdEnts)
	local emods = ent.EntityMods
	if not emods then return end
	if WireAddon then
		WireLib.ApplyDupeInfo(ply, ent, emods.WireDupeInfo, function(id) return createdEnts[id] end)
	end
	ent.SPL = ply
end